package ${package}.${moduleName}.controller.api;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import ${package}.${moduleName}.entity.${ClassName};
import ${package}.${moduleName}.service.${ClassName}Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;


/**
* ${tableComment}
*
* @author ${author} ${email}
* @since ${version} ${date}
*/
@RestController
@RequestMapping("${moduleName}/${functionName}")
@Api(tags = "${ClassName}")
public class ${ClassName}Controller {

    @Autowired
    private ${ClassName}Service ${className}Service;

   /**
    * 分页查询${tableComment}
    *
    * @param page 分页信息
    * @return IPage<${ClassName}Response> ${tableComment}列表分页
    */
    @GetMapping("page${ClassName}")
    @ApiOperation("分页查询${tableComment}")
    public ResultReply<IPage<${ClassName}Response>> page${ClassName}(${ClassName}PageRequest page){
        return ResultReply.onOk(${className}Service.page${ClassName}(page));
    }

    /**
    * 根据id获取${tableComment}信息
    *
    * @param id ${tableComment}id
    * @return ${ClassName}Response ${tableComment}
    */
    @GetMapping("get${ClassName}Detail/{id}")
    @ApiOperation("根据id获取${tableComment}信息")
    @ApiImplicitParam(name = "id", value = "${tableComment}id", required = true, dataType = "Long", dataTypeClass = Long.class, paramType = "path")
    public ResultReply<${ClassName}Response> get${ClassName}Detail(@PathVariable("id") Long id) {
        return ResultReply.onOk(${className}Service.get${ClassName}Detail(id));
    }

    /**
    * 新增${tableComment}
    *
    * @param ${ClassName?uncap_first}Request ${tableComment}
    * @return
    */
    @PostMapping("add${ClassName}")
    @ApiOperation("新增${tableComment}")
    public ResultReply<Boolean> add${ClassName}(@Validated @RequestBody ${ClassName}Request ${ClassName?uncap_first}Request) {
        return ResultReply.onOk(${className}Service.save${ClassName}(${ClassName?uncap_first}Request));
    }

    /**
    * 修改${tableComment}
    *
    * @param ${ClassName?uncap_first}Request  ${tableComment}
    * @return
    */
    @PutMapping("update${ClassName}")
    @ApiOperation("修改${tableComment}")
    public ResultReply<Boolean> update${ClassName}(@Validated @RequestBody ${ClassName}Request ${ClassName?uncap_first}Request) {
        return ResultReply.onOk(${className}Service.update${ClassName}(${ClassName?uncap_first}Request));
    }

    /**
    * 根据id删除${tableComment}
    *
    * @param id 实体ID
    * @return false-失败 true-成功
    */
    @DeleteMapping("del${ClassName}/{id}")
    @ApiOperation("根据id删除${tableComment}")
    @ApiImplicitParam(name = "id", value = "${tableComment}id", required = true, dataType = "Long", dataTypeClass = Long.class, paramType = "path")
    public ResultReply<Boolean> del${ClassName}(@PathVariable("id") Long id) {
        return ResultReply.onOk(${className}Service.batchdel${ClassName}(Arrays.asList(id)));
    }

    /**
    * 批量删除${tableComment}
    *
    * @param idlist id集合
    * @return false-失败 true-成功
    */
    @DeleteMapping("batchdel${ClassName}")
    @ApiOperation("批量${tableComment}")
    public ResultReply<Boolean> batchdel${ClassName}(
       @ApiParam(name = "idlist", value = "${tableComment}id集合", required = true)
       @NotNull(message = "${tableComment}id集合不能为空") @RequestBody List<Long> idlist) {
        return ResultReply.onOk(${className}Service.batchdel${ClassName}(idlist));
    }
}